package com.zxy.barometer.message.response;

import com.zxy.barometer.common.config.MessageResultConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @author zxy
 */
@Data
@ApiModel(value = "基础响应model")
public class BaseResult {
    @ApiModelProperty(value = "响应编码 0000为成功", example = "0000")
    private String code = "0000";
    @ApiModelProperty(value = "响应信息", example = "成功")
    private String message = "成功";
    @ApiModelProperty(value = "响应时间")
    private Long responseTime = System.currentTimeMillis() / 1000L;

    public BaseResult() {
    }

    public BaseResult(String status, String message) {
        if (StringUtils.equals(status, MessageResultConstant.SUCCESS)) {
            this.code = "0000";
            this.message = StringUtils.isBlank(message) ? "成功" : message;
        } else if (StringUtils.equals(status, MessageResultConstant.DATA_ERROR)) {
            this.code = "1000";
            this.message = StringUtils.isBlank(message) ? "数据错误" : message;
        } else if (StringUtils.equals(status, MessageResultConstant.ERROR)) {
            this.code = "2000";
            this.message = StringUtils.isBlank(message) ? "系统错误" : message;
        } else if (StringUtils.equals(status, MessageResultConstant.NULL_ERROR)) {
            this.code = "3000";
            this.message = StringUtils.isBlank(message) ? "请求字段包含空" : message;
        } else if (StringUtils.equals(status, MessageResultConstant.SIGN_ERROR)) {
            this.code = "4000";
            this.message = StringUtils.isBlank(message) ? "签名错误" : message;
        } else if (StringUtils.equals(status, MessageResultConstant.VERSION_ERROR)) {
            this.code = "5000";
            this.message = StringUtils.isBlank(message) ? "版本错误" : message;
        } else {
            this.code = "9999";
            this.message = StringUtils.isBlank(message) ? "一股神秘未知的力量" : message;
        }
    }
}
